package com.lmiot.xyclick.Activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.MenuItem;
import android.widget.FrameLayout;
import com.lmiot.xyclick.AD.SDK.ADSDK;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Bean.InitFloatBean;
import com.lmiot.xyclick.Bean.PushResultBean;
import com.lmiot.xyclick.Bind.FloatFragment;
import com.lmiot.xyclick.Fragment.AutoFragment;
import com.lmiot.xyclick.Fragment.HomeFragment;
import com.lmiot.xyclick.Fragment.SettingFragment;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.Share.ShareFragment;
import com.lmiot.xyclick.Util.ActivityUtil;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.DebugUtli;
import com.lmiot.xyclick.Util.FileUtils;
import com.lmiot.xyclick.Util.HttpUtilNew;
import com.lmiot.xyclick.Util.LayoutDialogUtil;
import com.lmiot.xyclick.Util.LogUtil;
import com.lmiot.xyclick.Util.PhoneUtil;
import com.lmiot.xyclick.Util.RawUtilsNew;
import com.lmiot.xyclick.Util.StateBarUtil;
import com.lmiot.xyclick.Util.TimeUtils;
import com.lmiot.xyclick.inteface.OnBasicListener;
import com.xiaoyi.intentsdklibrary.Bean.TopClickTypeBean;
import com.xiaoyi.intentsdklibrary.CheckUtil;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionJni;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.CirCleViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.NormalTopViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.PathViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.RectViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.TopViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.TopViewSDKShort;
import com.xiaoyi.jni.JNITest;
import com.yhao.floatwindow.FloatUtil;
import com.youyi.yypermissionlibrary.SDK.YYPerUtils;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import com.youyi.yyviewsdklibrary.LoadingDialog;
import java.security.MessageDigest;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity extends BaseActivity {
    private static final String TAG = "MainActivity";
    private AutoFragment mAutoFragment;
    private Fragment mFloatFragment;
    private HomeFragment mHomeFragment;
    FrameLayout mIdMainFramelayout;
    BottomNavigationView mNavigation;
    private SettingFragment mSettingFragment;
    private ShareFragment mShareFragment;

    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.SupportActivity, android.support.v4.app.FragmentActivity, com.lmiot.xyclick.Activity.BaseActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_main);
        initView();
        initFirstData();
        startMethod();
        reSetSlipTime();
        if (!ADSDK.mIsGDT) {
            checkNotic();
        }
//        if (!DebugUtli.isDebugVersion(MyApp.getInstance())) {
//            ActionJni.init(MyApp.getContext());
//        }
        EventBus.getDefault().post(new InitFloatBean(InitFloatBean.FloatType.action));
        EventBus.getDefault().post(new InitFloatBean(InitFloatBean.FloatType.hand));
        EventBus.getDefault().post(new InitFloatBean(InitFloatBean.FloatType.handPlus));
        EventBus.getDefault().post(new InitFloatBean(InitFloatBean.FloatType.track));
        EventBus.getDefault().post(new InitFloatBean(InitFloatBean.FloatType.record));
        EventBus.getDefault().post(new InitFloatBean(InitFloatBean.FloatType.pause));
        EventBus.getDefault().post(new InitFloatBean(InitFloatBean.FloatType.menu));
        if (!DebugUtli.isDebugVersion(MyApp.getInstance())) {
            new Handler().postDelayed(new Runnable() {
                public void run() {
                    JNITest.xyInit(MyApp.getContext());
                }
            }, 0);
        }
//        checkOffLine();
    }

    private void checkOffLine() {
        if (!DataUtil.getUserRetist(MyApp.getContext())) {
            HttpUtilNew.getInstance().regist(new OnBasicListener() {
                @Override // com.lmiot.xyclick.inteface.OnBasicListener
                public void result(boolean z, String str) {
                }
            });
        } else if (!TextUtils.isEmpty(DataUtil.getSessionID(MyApp.getContext()))) {
            LogUtil.d(TAG, "checkOffLine=" + PhoneUtil.getIMEI(MyApp.getContext()));
            HttpUtilNew.getInstance().findUserBean(new HttpUtilNew.OnUserBeanListener() {

                @Override // com.lmiot.xyclick.Util.HttpUtilNew.OnUserBeanListener
                public void result(boolean z) {
                    if (!DataUtil.getUserEnable(MainActivity.this)) {
                        MainActivity.this.showPayDialog("当前账号已注销，暂时无法使用，继续注册请联系管理员！");
                    }
                }
            }, new HttpUtilNew.OnOffLine() {
                /* class com.lmiot.xyclick.Activity.MainActivity.AnonymousClass3 */

                @Override // com.lmiot.xyclick.Util.HttpUtilNew.OnOffLine
                public void result(boolean z) {
                    if (z && DataUtil.getLoginByWx(MyApp.getContext())) {
                        LayoutDialogUtil.showSureDialog(MainActivity.this, "请重新登录", "您的登录信息已经过期，请重新登录！\n如非本人操作，则可能多个设备ID重复导致，请截图联系发邮件给管理员处理！", true, false, "退出系统", "前往登录", new LayoutDialogUtil.OnResultClickListener() {
                            /* class com.lmiot.xyclick.Activity.MainActivity.AnonymousClass3.AnonymousClass1 */

                            @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                            public void result(boolean z) {
                                if (z) {
                                    ActivityUtil.skipActivity(MainActivity.this, LoginActivity.class);
                                } else {
                                    MyApp.getInstance().exit();
                                }
                            }
                        });
                    }
                }
            });
        }
    }

    private void checkNotic() {
        if (DataUtil.nowNoicBean != null) {
            String noticID = DataUtil.nowNoicBean.getNoticID();
            if (!DataUtil.getHasReadNoticID(MyApp.getContext(), noticID)) {
                DataUtil.setHasReadNoticID(MyApp.getContext(), noticID, true);
                LayoutDialogUtil.showSureDialog(this, "系统公告", DataUtil.nowNoicBean.getNoticMsg(), DataUtil.nowNoicBean.getNoticLevel() == 1, false, "返回", "确定", new LayoutDialogUtil.OnResultClickListener() {
                    /* class com.lmiot.xyclick.Activity.MainActivity.AnonymousClass5 */

                    @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                    public void result(boolean z) {
                        if (z && !TextUtils.isEmpty(DataUtil.nowNoicBean.getNoticUrl())) {
                            ActionNormalSDK.getInstance().openWeb(MainActivity.this, DataUtil.nowNoicBean.getNoticUrl());
                        }
                    }
                });
            }
        }
    }

    private void reSetSlipTime() {
        int slip = FloatUtil.getSlip(this);
        if (slip == 0 || slip == 1) {
            FloatUtil.setSlip(this, 50);
        } else if (slip == 2) {
            FloatUtil.setSlip(this, 200);
        } else if (slip == 3) {
            FloatUtil.setSlip(this, 300);
        } else if (slip == 4) {
            FloatUtil.setSlip(this, 500);
        } else if (slip == 5) {
            FloatUtil.setSlip(this, 700);
        }
    }

    private void startMethod() {
        getWindow().addFlags(128);
        StateBarUtil.immersive(this, getResources().getColor(R.color.colorAccent));
        StateBarUtil.setPadding(this, this.mIdMainFramelayout);
        setMenu();
        EventBus.getDefault().register(this);
    }

    private void initFirstData() {
        if (DataUtil.getVip(MyApp.getContext()) && YYPerUtils.hasSD() && TextUtils.isEmpty(DataUtil.getSessionID(MyApp.getContext()))) {
            DataUtil.setLoginByWx(MyApp.getContext(), false);
            DataUtil.setSessionID(MyApp.getContext(), TimeUtils.createSessionID());
        }
        new Thread() {
            /* class com.lmiot.xyclick.Activity.MainActivity.AnonymousClass6 */

            public void run() {
                if (DataUtil.getFisrtData(MainActivity.this)) {
                    FileUtils.checkFolder();
                    DataUtil.setFisrtData(MainActivity.this, false);
                    RawUtilsNew.getAllRawFile();
                    FileUtils.resetLocalData(new OnBasicListener() {
                        /* class com.lmiot.xyclick.Activity.MainActivity.AnonymousClass6.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.inteface.OnBasicListener
                        public void result(boolean z, String str) {
                        }
                    });
                    MainActivity.this.initNormalData();
                } else if (DataUtil.getFirstVersionData(MainActivity.this, PhoneUtil.getAPPVersion())) {
                    FileUtils.checkFolder();
                    DataUtil.setFirstVersionData(MainActivity.this, PhoneUtil.getAPPVersion(), false);
                    FileUtils.resetLocalData(new OnBasicListener() {
                        /* class com.lmiot.xyclick.Activity.MainActivity.AnonymousClass6.AnonymousClass2 */

                        @Override // com.lmiot.xyclick.inteface.OnBasicListener
                        public void result(boolean z, String str) {
                        }
                    });
                }
            }
        }.start();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void initNormalData() {
        DataUtil.setDirectData(MyApp.getContext(), "click", "{\n  \"actionName\": \"自动化列表\",\n  \"actionType\": \"key_now_auto_list\",\n  \"delay\": 0,\n  \"detail\": \"{\\\"MaxNum\\\":0,\\\"MinNum\\\":0,\\\"druation\\\":0,\\\"offsetX\\\":0,\\\"offsetY\\\":0,\\\"repeat\\\":0,\\\"sortNum\\\":0,\\\"value\\\":0}\",\n  \"enable\": true,\n  \"sortNum\": 0,\n  \"useTime\": 0\n}");
        DataUtil.setDirectData(MyApp.getContext(), "left", "{\n  \"actionName\": \"微信\",\n  \"actionType\": \"key_app\",\n  \"delay\": 0,\n  \"detail\": \"{\\\"MaxNum\\\":0,\\\"MinNum\\\":0,\\\"druation\\\":0,\\\"offsetX\\\":0,\\\"offsetY\\\":0,\\\"packName\\\":\\\"com.tencent.mm\\\",\\\"repeat\\\":0,\\\"sortNum\\\":0,\\\"value\\\":0}\",\n  \"enable\": true,\n  \"sortNum\": 0,\n  \"useTime\": 0\n}");
    }

    private void setMenu() {
        this.mHomeFragment = new HomeFragment(this);
        this.mAutoFragment = new AutoFragment(this);
        this.mFloatFragment = new FloatFragment(this);
        this.mShareFragment = new ShareFragment(this);
        this.mSettingFragment = new SettingFragment(this);
        if (ADSDK.mIsGDT) {
            this.mNavigation.getMenu().removeItem(R.id.id_menu_share);
        } else if (!ADSDK.showShare) {
            this.mNavigation.getMenu().removeItem(R.id.id_menu_share);
        }
        MainActivityHelper.disableShiftMode(this.mNavigation);
        this.mNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {

            @Override // android.support.design.widget.BottomNavigationView.OnNavigationItemSelectedListener
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                    case R.id.id_menu_auto /*{ENCODED_INT: 2131296769}*/:
                        MainActivity.this.getSupportFragmentManager().beginTransaction().replace(R.id.id_main_framelayout, MainActivity.this.mAutoFragment).commitAllowingStateLoss();
                        return true;
                    case R.id.id_menu_float /*{ENCODED_INT: 2131296770}*/:
                        MainActivity.this.getSupportFragmentManager().beginTransaction().replace(R.id.id_main_framelayout, MainActivity.this.mFloatFragment).commitAllowingStateLoss();
                        return true;
                    case R.id.id_menu_home /*{ENCODED_INT: 2131296771}*/:
                        MainActivity.this.getSupportFragmentManager().beginTransaction().replace(R.id.id_main_framelayout, MainActivity.this.mHomeFragment).commitAllowingStateLoss();
                        return true;
                    case R.id.id_menu_setting /*{ENCODED_INT: 2131296772}*/:
                        MainActivity.this.getSupportFragmentManager().beginTransaction().replace(R.id.id_main_framelayout, MainActivity.this.mSettingFragment).commitAllowingStateLoss();
                        return true;
                    case R.id.id_menu_share /*{ENCODED_INT: 2131296773}*/:
                        MainActivity.this.getSupportFragmentManager().beginTransaction().replace(R.id.id_main_framelayout, MainActivity.this.mShareFragment).commitAllowingStateLoss();
                        return true;
                    default:
                        return true;
                }
            }
        });
        this.mNavigation.setSelectedItemId(R.id.id_menu_auto);
    }

    @Override // android.support.v4.app.FragmentActivity, com.lmiot.xyclick.Activity.BaseActivity
    public void onResume() {
        super.onResume();
        try {
            if (!TextUtils.isEmpty(getIntent().getStringExtra("flag"))) {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        if (MainActivity.this.mNavigation != null) {
                            MainActivity.this.mNavigation.setSelectedItemId(R.id.id_menu_auto);
                        }
                    }
                }, 200);
            }
            if (CheckUtil.checkOp(this)) {
                CirCleViewSDK.getInstance().init(MyApp.getContext());
                TopViewSDKShort.getInstance().init(MyApp.getContext());
                TopViewSDK.getInstance().init(MyApp.getContext());
                NormalTopViewSDK.getInstance().init(MyApp.getContext());
                RectViewSDK.getInstance().init(MyApp.getContext());
                PathViewSDK.getInstance().init(MyApp.getContext());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getSignature(Context context) {
        try {
            return encryptionMD5(context.getPackageManager().getPackageInfo(context.getPackageName(), 64).signatures[0].toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String encryptionMD5(byte[] bArr) {
        StringBuffer stringBuffer = new StringBuffer();
        try {
            MessageDigest instance = MessageDigest.getInstance("MD5");
            instance.reset();
            instance.update(bArr);
            byte[] digest = instance.digest();
            for (int i = 0; i < digest.length; i++) {
                if (Integer.toHexString(digest[i] & -1).length() == 1) {
                    stringBuffer.append("0");
                    stringBuffer.append(Integer.toHexString(digest[i] & -1));
                } else {
                    stringBuffer.append(Integer.toHexString(digest[i] & -1));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return stringBuffer.toString();
    }

    private void showPayDialog(String str) {
        new AlertDialog.Builder(this).setMessage(str).setCancelable(false).setNegativeButton("邮件联系", new DialogInterface.OnClickListener() {
            /* class com.lmiot.xyclick.Activity.MainActivity.AnonymousClass10 */

            public void onClick(DialogInterface dialogInterface, int i) {
                MainActivity.this.sendMail();
            }
        }).setPositiveButton("退出应用", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                MyApp.getInstance().exit();
            }
        }).create().show();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void sendMail() {
        try {
            String str = DataUtil.getVip(MyApp.getContext()) ? "V" : "";
            Intent intent = new Intent("android.intent.action.SENDTO");
            intent.setData(Uri.parse("mailto:809202631@qq.com"));
            intent.putExtra("android.intent.extra.SUBJECT", getString(R.string.bmd) + PhoneUtil.getAPPVersion());
            intent.putExtra("android.intent.extra.TEXT", getString(R.string.pbb) + PhoneUtil.getBrand() + "\n" + getString(R.string.pdn) + PhoneUtil.getModel() + "\n【手机版本】: Android" + PhoneUtil.getSystemVersion() + str + "\n【用户信息】:" + PhoneUtil.getIMEI(MyApp.getContext()) + "\n【软件版本】:" + PhoneUtil.getAPPVersion() + "\n" + getString(R.string.qsn));
            startActivity(intent);
        } catch (Exception e) {
            ToastUtil.err(getString(R.string.pnsp));
            e.printStackTrace();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(PushResultBean pushResultBean) {
        try {
            String resultType = pushResultBean.getResultType();
            char c = 65535;
            int hashCode = resultType.hashCode();
            if (hashCode != -2142381090) {
                if (hashCode != -1791190732) {
                    if (hashCode == -769048285) {
//                        if (resultType.equals(PushUtils.PUSH_RESULT_FAIL)) {
//                            c = 1;
//                        }
                    }
                }
            }
            if (c == 0) {
                LoadingDialog.hidden();
                ToastUtil.success("分享成功！");
            } else if (c == 1) {
                LoadingDialog.hidden();
                ToastUtil.err("分享失败，请检查ID和网络情况！");
            } else if (c == 2) {
                AutoFragment autoFragment = this.mAutoFragment;
                if (autoFragment != null && autoFragment.isVisible()) {
                    this.mAutoFragment.changeDagta();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void refreshView() {
        onResume();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(TopClickTypeBean topClickTypeBean) {
        onResume();
    }

    private void initView() {
        this.mIdMainFramelayout = (FrameLayout) findViewById(R.id.id_main_framelayout);
        this.mNavigation = (BottomNavigationView) findViewById(R.id.navigation);
    }
}
